home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-06 / charon40.zip / LF2CRLF.C < prev    next >
Text File  |  1992-03-27  |  2KB  |  71 lines

  1. /* lf2crlf.c -- translator for use with Charon
  2.     Copyright (C) 1992 Brad K. Clements, Clarkson University
  3.            All Rights Reserved.
  4.  
  5. */
  6. #define    DEBUG    1
  7.  
  8. #include <ctype.h> 
  9. #include <time.h>
  10. #include <string.h>
  11. #define    STANDALONE    0
  12. #include "callback.h"
  13. #include "tagvalue.h"
  14.  
  15. char    *stackinfo="$STACKSIZE:4096";
  16.  
  17. /* Usage:
  18.     converts LF to CRLF
  19. */
  20.  
  21. #define    BUFFSIZE    1024
  22.  
  23. int
  24. main(int argc, char *argv[])
  25. {
  26.     int     rc;
  27.     char        ibuffer[BUFFSIZE], obuffer[BUFFSIZE];
  28.     char        *inc, *outc, *inlimit, *outlimit;
  29.     int        incount;
  30.     long        start = time(NULL);
  31.     long        inbytes, outbytes;
  32.  
  33.     inbytes = outbytes = 0;
  34.     outc = obuffer;
  35.     outlimit = obuffer + BUFFSIZE - 4;
  36.     while(1) {
  37.         incount = read(STDIN, ibuffer, BUFFSIZE);
  38. #ifdef    DEBUGX
  39.     fprintf(STDERR,"Read %d bytes\n",incount);
  40. #endif
  41.         if(incount < 1)
  42.                    break;        /* we're done */
  43.         inlimit = ibuffer + incount;
  44.          inbytes += incount;
  45.          for(inc = ibuffer; inc < inlimit; inc++) {
  46.             if( *inc == 10)
  47.                        *outc++ = 13;
  48.             *outc++ = *inc;
  49.             if(outc >= outlimit) {
  50. #ifdef    DEBUGX
  51.     fprintf(STDERR,"writing %d bytes\n",outc - obuffer);
  52. #endif
  53.                        outbytes += (outc - obuffer);
  54.                        write(STDOUT, obuffer, outc - obuffer);
  55.                 outc = obuffer;
  56.             }
  57.            }
  58.            if(incount < BUFFSIZE)
  59.                   break;
  60.        }
  61.     if(outc > obuffer) {
  62.                write(STDOUT, obuffer, outc - obuffer);
  63.         outbytes += (outc - obuffer);
  64.     }
  65.     start = time(NULL) - start;
  66.     fprintf(STDERR,"Converted %ld inbytes to %ld outbytes in %ld seconds.\n",
  67.                inbytes, outbytes, start);
  68.           return(RT_OK|RT_CHANGED_TEXT); 
  69. }
  70.  
  71.